﻿@{
    Layout = "~/Views/Shared/PlanPartial/_LayoutEmpty.cshtml";
}
@using Wicresoft.UnifyShow.Business;
@{
    var IsGlobalAdmin = (bool)ViewBag.IsGlobalAdmin;
    var location = ViewData["Location"] as SiteBranchModel;
    var locationList = ViewData["LocationList"] as List<PlanLocationOwner>;
}
<div class="padding20">
    <div class="padding5">
        开始时间:
        <input type="text" class="easyui-datebox" id="startDate" />
    </div>
    <div class="padding5">
        结束时间:
        <input type="text" class="easyui-datebox" id="endDate" />
    </div>


    <div class="padding5">
        查询单位:
             @if (IsGlobalAdmin)
             {
                 <select style="width: 153px;" id="locaitonList">
                     @foreach (var item in locationList)
                     { 
                         <option value="@(item.LocationID)">@(item.Alias)</option>
                     }
                 </select>
             }
             else
             {
                 <input type="hidden" value="@(location != null ? location.ID : 0)" id="locaitonList" />
                 <input type="text" disabled="disabled" id="locaitonName" value="@(location != null ? location.Name : "")" />
             }
        <input type="button" value="查询" onclick="startSearch()" />
    </div>


    <div class="padding5">
        <table id="DutyPlanList" style="height: 350px;" class="" title="值班记录" pagination="true"
            fitcolumns="true" singleselect="true">
            <thead>
                <tr>
                    <th field="ID" hidden="true"></th>
                    <th field="LocationName" width="100">单位</th>
                    <th field="DutyDay" formatter="DateFormate" width="80">日期</th>
                    <th field="WatchKeeper" width="80">值班人</th>
                    <th field="DutyPhone" width="80">值班电话</th>
                    <th field="ModifyBy" sortable="true" width="80">记录人</th>
                    <th field="DailyRecord" sortable="true" width="180">值班记录摘要</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

<script type="text/javascript">
    var DateFormate = function (value, row, index) {
        if (value) {
            return value.DateStringConvert('yyyy-MM-dd');
        }
    };

    var startSearch = function () {
        var query = {
            startDate: $('#startDate').datebox('getValue'),
            endDate: $('#endDate').datebox('getValue'),
            locationID: $('#locaitonList').val()
        };
        $('#DutyPlanList').datagrid('load', query);
    }

    $(function () {
        $('.easyui-datebox').datebox({
            formatter: function (date) {
                return date.formate('yyyy-MM-dd')
            }
        });

        var today = new Date();
        var firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
        $('#startDate').datebox('setValue', firstDay.formate());
        $('#endDate').datebox('setValue', new Date().formate());

        $('.combo-text').attr('disabled', true);

        var query = {
            startDate: $('#startDate').datebox('getValue'),
            endDate: $('#endDate').datebox('getValue'),
            locationID: $('#locaitonList').val()
        };

        $('#DutyPlanList').datagrid({
            url: '/DutyPlan/GetDutyPlanList',
            pageList: [10],
            pageSize: 10,
            pageNumber: 1,
            queryParams: query,
            onDblClickRow: function (rowIndex, rowData) {
                showModuleDialog('/DutyPlan/Edit?ID=' + rowData["ID"] + '&Status=VIEW');
            }
        });

        var p2 = $('#DutyPlanList').datagrid('getPager');
        $(p2).pagination({
            beforePageText: '第',
            afterPageText: '页&nbsp;共&nbsp;{pages}&nbsp;页',
            displayMsg: '当前显示{from} - {to}&nbsp;条记录&nbsp;共&nbsp;{total}&nbsp;条记录'

        });
    });
</script>
